package com.it.controller;

import com.alibaba.fastjson.JSON;
import com.it.pojo.DDepartment;
import com.it.service.DDepartmentService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(value = "/depAll")
public class DDepartmentController {
    @Resource
    DDepartmentService dDepartmentService;

    //查询所有科室
    @RequestMapping(value = "/DDepartmentQueryAll",method = RequestMethod.GET)
    public Object DDepartmentQueryAll(){
        List<DDepartment> dDepartments = dDepartmentService.DDepartmentQueryAll();
        String depJSONString = JSON.toJSONString(dDepartments);
        return depJSONString;
    }
    //根据id查询
    @RequestMapping(value = "/DDepartmentById/{id}",method = RequestMethod.GET)
    public Object DDepartmentById(@PathVariable Integer id){
        DDepartment dDepartment = dDepartmentService.DDepartmentById(id);
        String dDepartments = JSON.toJSONString(dDepartment);
        return dDepartments;
    }
    //根据科室名模糊查询
    @RequestMapping(value = "/DDepartmentLikeName/{name}",method = RequestMethod.GET)
    public Object DDepartmentLikeName(@PathVariable String name){
        List<DDepartment> dDepartments = dDepartmentService.DDepartmentLikeName(name);
        String dDepartmentslist = JSON.toJSONString(dDepartments);
        return dDepartmentslist;
    }
    //新增科室
    @RequestMapping(value = "/addDDepartment",method = RequestMethod.POST)
    public int addDDepartment(DDepartment dDepartment){
        return dDepartmentService.addDDepartment(dDepartment);
    }
    //修改科室
    @RequestMapping(value = "/updateDDepartment",method = RequestMethod.POST)
    public int updateDDepartment(DDepartment dDepartment){
        return dDepartmentService.updateDDepartment(dDepartment);
    }
    //删除科室
    @RequestMapping(value = "/deleteDDepartment/{id}",method = RequestMethod.POST)
    public int deleteDDepartment(@PathVariable Integer id){
        return dDepartmentService.deleteDDepartment(id);
    }
}
